package com.zhengxyou.jetpackdemo.paging;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.zhengxyou.jetpackdemo.R;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

public class PagingActivity extends AppCompatActivity {
    private int currentPage = 0;
    PagingAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_paging);
        RecyclerView rv_list = findViewById(R.id.rv_list);
        rv_list.setHasFixedSize(true);
        rv_list.setLayoutManager(new LinearLayoutManager(this));
        adapter = new PagingAdapter();

        PagingViewModel viewModel = ViewModelProviders.of(this).get(PagingViewModel.class);

        viewModel.userList.observe(this, users -> adapter.submitList(users));

        rv_list.setAdapter(adapter);
    }

    public static void start(Context context) {
        Intent starter = new Intent(context, PagingActivity.class);
        context.startActivity(starter);
    }
}
